package com.eshop.modules.system.service.impl;

import java.io.IOException;
import java.util.Iterator;
import com.eshop.utils.FileUtil;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.system.service.dto.UserAvatarDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.system.service.dto.UserAvatarQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.system.service.UserAvatarService;
import com.eshop.modules.system.domain.UserAvatar;
import com.eshop.modules.system.service.mapper.UserAvatarMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class UserAvatarServiceImpl extends BaseServiceImpl<UserAvatarMapper, UserAvatar> implements UserAvatarService
{
    private final IGenerator generator;
    
    public Map<String, Object> queryAll(final UserAvatarQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<UserAvatar> page = (PageInfo<UserAvatar>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)UserAvatarDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<UserAvatar> queryAll(final UserAvatarQueryCriteria criteria) {
        return (List<UserAvatar>)((UserAvatarMapper)this.baseMapper).selectList(QueryHelpPlus.getPredicate(UserAvatar.class, criteria));
    }
    
    public void download(final List<UserAvatarDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final UserAvatarDto userAvatar : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("真实文件名", userAvatar.getRealName());
            map.put("路径", userAvatar.getPath());
            map.put("大小", userAvatar.getSize());
            map.put("创建时间", userAvatar.getCreateTime());
            map.put("真实文件名", userAvatar.getRealName());
            map.put("路径", userAvatar.getPath());
            map.put("大小", userAvatar.getSize());
            map.put("创建时间", userAvatar.getCreateTime());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public UserAvatar saveFile(final UserAvatar userAvatar) {
        return null;
    }
    
    public UserAvatarServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
